848E - Days of Floral Colours - CodeForces Solution


combinatorics divide and conquer dp fft math *3400

Please click on ads to support us..

C++ Code:

#include<iostream>
#define mod 998244353 
#define int long long
using namespace std;
int flowerColorsCount;
int intermediateResults[16] = { 0, 4, 8, -1, 16, -10, 4, -12, -48, 26, -44, 15, -16, -4, -4, -1 };
int beautySums[16] = { 0, 0, 0, 24, 4, 240, 204, 1316, 2988, 6720, 26200, 50248, 174280, 436904, 1140888, 3436404 };
main() {
	cin >> flowerColorsCount;
	for (int colorIndex = 16; colorIndex <= flowerColorsCount; colorIndex++) {
		int intermediateSum = 0;
		for (int resultIndex = 0; resultIndex < 16; resultIndex++) intermediateSum = (intermediateSum + 1ll * intermediateResults[(colorIndex - resultIndex - 1) & 15] * beautySums[resultIndex] % mod) % mod;
		beautySums[colorIndex & 15] = intermediateSum;
	} cout << (beautySums[flowerColorsCount & 15] + mod) % mod;
}/*1694990382.9800775*/


Comments

Submit
0 Comments
More Questions

680B - Bear and Finding Criminals
1036E - Covered Points
1015D - Walking Between Houses
155B - Combination
1531A - Зингер | color
1678A - Tokitsukaze and All Zero Sequence
896A - Nephren gives a riddle
761A - Dasha and Stairs
1728B - Best Permutation
1728A - Colored Balls Revisited
276B - Little Girl and Game
1181A - Chunga-Changa
1728C - Digital Logarithm
1728D - Letter Picking
792B - Counting-out Rhyme
1195A - Drinks Choosing
5D - Follow Traffic Rules
1272A - Three Friends
1632D - New Year Concert
1400D - Zigzags
716C - Plus and Square Root
412A - Poster
844B - Rectangles
1591A - Life of a Flower
1398C - Good Subarrays
629A - Far Relative’s Birthday Cake
1166A - Silent Classroom
1000B - Light It Up
218B - Airport
1463B - Find The Array